package com.example.SolveRedundantCode;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * <pre>
 * 功能描述：改造前
 * </pre>
 *
 * @author: 李明杰
 * @date: 2023/3/7 23:08
 */
@Slf4j
public class FtpProviderImpl implements FtpProvider {

    private FTPClient ftpClient;

    @Override
    public String[] listDirectories(String parentDirectory) {
        try {
            ftpClient.connect("host", 22);
            ftpClient.login("username", "password");
            return ftpClient.listDirectories(parentDirectory);
        } catch (IOException ex) {
            log.error("Something went wrong", ex);
            throw new RuntimeException(ex);
        } finally {
            ftpClient.logout();
            ftpClient.disconnect();
        }
    }

    @Override
    public boolean deleteFile(String filePath) {
        try {
            ftpClient.connect("host", 22);
            ftpClient.login("username", "password");
            return ftpClient.deleteFile(filePath);
        } catch (IOException e) {
            log.error("Something went wrong", e);
            throw new RuntimeException(e);
        } finally {
            ftpClient.logout();
            ftpClient.disconnect();
        }
    }
}
